/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.StockBalanceDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import com.minierp.model.StockBalance;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class StockBalanceDaoImpl extends BaseDaoImpl implements StockBalanceDao {
	public List<?> getList(long productId, long storehouseId, Date startDate) {
		String sql = "from com.minierp.model.StockBalance as obj where obj.productId = "
				+ productId
				+ " and obj.storehouseId="
				+ storehouseId
				+ " and obj.balanceDate>:balanceDate"
				+ " order by obj.balanceDate";
		Session sess = null;

		List arg9;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			q.setDate("balanceDate", startDate);
			arg9 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg9;
	}

	public StockBalance getPreviousBalance(long productId, long storehouseId,
			Date startDate) {
		String sql = "from com.minierp.model.StockBalance as obj where obj.productId = "
				+ productId
				+ " and obj.storehouseId="
				+ storehouseId
				+ " and obj.balanceDate<=:balanceDate"
				+ " order by obj.balanceDate desc";
		Session sess = null;

		StockBalance arg10;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			q.setDate("balanceDate", startDate);
			q.setFirstResult(0);
			q.setMaxResults(1);
			List list = q.list();
			if (list.isEmpty()) {
				return null;
			}

			arg10 = (StockBalance) list.get(0);
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg10;
	}

	public List<?> getPreviousList(long storehouseId, Date startDate) {
		String sql = "from com.minierp.model.StockBalance as obj where obj.storehouseId="
				+ storehouseId
				+ " and obj.balanceDate<=:balanceDate"
				+ " order by obj.balanceDate desc";
		Session sess = null;

		List arg7;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			q.setDate("balanceDate", startDate);
			arg7 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg7;
	}

	public List<?> getList(long storehouseId, Date balanceDate) {
		String sql = "from com.minierp.model.StockBalance as obj where obj.storehouseId="
				+ storehouseId
				+ " and obj.balanceDate=:balanceDate"
				+ " order by obj.id";
		Session sess = null;

		List arg7;
		try {
			sess = this.getSession();
			Query q = sess.createQuery(sql);
			q.setDate("balanceDate", balanceDate);
			arg7 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg7;
	}
}